package com.fz.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fz.entity.Repair;
import com.fz.entity.Topic;
import com.fz.service.TopicService;
import com.fz.vo.ResultVo;


import javax.annotation.Resource;
import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 存储话题信息 前端控制器
 * </p>
 *
 * @author hyr
 * @since 2025-06-18
 */
@RestController
@RequestMapping("/topic")
public class TopicController {
    @Resource
    TopicService topicService;
    @GetMapping("/list1")
    public ResultVo<List<Topic>>list1(){
        return ResultVo.success(topicService.list());
    }


    // 创建话题（群聊）
    @PostMapping("/add")
    public ResultVo<Topic> createTopic( Long userId, String title,String content) {
        Topic topic =topicService.createTopic(userId, title,content);
        return ResultVo.success(topic,"发布话题成功");
    }

    // 获取所有话题分组（按标题分组）
    @GetMapping("/groups")
    public List<Topic> getTopicGroups(String title){
        return topicService.list(title);
    }

    // 获取单个话题详情（群聊详情）
    @GetMapping("/detail")
    public ResultVo<Topic> getTopicDetail(Long id) {
        Topic topic = topicService.getById(id);
        return ResultVo.success(topic);
    }

    // 话题点赞
    @PostMapping("/like")
    public ResultVo<Boolean> likeTopic(Long id) {
        return ResultVo.success(topicService.likeTopic(id));
    }
}

